﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Linq;
using System.Text;

namespace CjcPhotoPrint
{
	public struct UnitSize
	{
		private double Centimeters { get; set; }

		public double Millimeters
		{
			get { return Centimeters * 10; }
			set { Centimeters = value / 10; }
		}

		public double Inches
		{
			get { return Centimeters * 0.39; }
			set { Centimeters = value / 0.39; }
		}
	}

	public class UnitSizeConverter : TypeConverter
	{
		public override bool CanConvertFrom( ITypeDescriptorContext context, Type sourceType )
		{
			return Type.GetTypeCode( sourceType ) == TypeCode.String;
		}

		public override object ConvertFrom( ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value )
		{
			if ( value == null ) return new UnitSize();
			if ( value is string ) return ConvertFromString( value as string );

			return (UnitSize)value;
		}

		public new object ConvertFromString( string text )
		{
			return new UnitSize { Inches = double.Parse( text ) };
		}
	}
}